
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DimCommodityGroup]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 drop table [dbo].[DimCommodityGroup]

GO

CREATE TABLE [dbo].[DimCommodityGroup] (
	[CommodityGroupKey] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL,
	[CommodityGroupIdentifier] [varchar] (20) NOT NULL,
	[CommodityGroupName] [nvarchar] (50) NOT NULL,
	[ParentCommodityGroupKey] [int] NOT NULL,

	CONSTRAINT [PK_CommodityGroup] PRIMARY KEY CLUSTERED (
		   [CommodityGroupKey]),

	CONSTRAINT [FK_CommodityGroup_ParentCommodityGroupKey] FOREIGN KEY ([ParentCommodityGroupKey]) REFERENCES [dbo].[DimCommodityGroup] ([CommodityGroupKey]) NOT FOR REPLICATION

)

GO

grant references, select, insert, delete, update on [dbo].[DimCommodityGroup] to [db_datawriter]

GO

grant select on [dbo].[DimCommodityGroup] to [public]

GO

